package com.miao.teacher.adapter;

import java.util.ArrayList;
import java.util.List;

import com.miao.teacher.app.TApp;
import com.miao.teacher.ui.R;
import com.miao.teacher.utils.FileUtil;


import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuAdapter extends BaseAdapter{
	private Context context=null;
	private List<String> mList=new ArrayList<String>();
	
	private LayoutInflater mInflater;
	
	private int mCurrentIndex=0;
	
	private int mGreen=Color.argb(255, 106, 180, 159);
	private int mBlack=Color.argb(155, 77, 77, 77);
	
	public MenuAdapter(Context c)
	{
		context=c;
		mInflater = (LayoutInflater) context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		String userName = FileUtil.getPreferences(context,
				TApp.Account_KEY);
		mList.add(userName);
		mList.add("批改历史");
		mList.add("学生评价");
		mList.add("批改示例");
		mList.add("批改要点");
		mList.add("更改密码");
		mList.add("退出登录");
	}
	public void setIndex(int index)
	{
		mCurrentIndex=index;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if(mList==null)
		{
			return 0;
		}
		return mList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		if(mList==null)
		{
			return null;
		}
		return mList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_menu, null);
			holder = new ViewHolder();
			holder.imgUser=(ImageView)convertView.findViewById(R.id.img_user);
			holder.tvTitle=(TextView)convertView.findViewById(R.id.tv_title);
			convertView.setTag(holder);
		}else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		if(arg0==0)
		{
			holder.imgUser.setVisibility(View.VISIBLE);
			holder.tvTitle.setTextColor(mGreen);
		}else
		{
			holder.imgUser.setVisibility(View.INVISIBLE);
		}
		if(mCurrentIndex==arg0&&arg0!=0)
		{
			holder.tvTitle.setTextColor(Color.WHITE);
			convertView.setBackgroundColor(mGreen);
			
		}else if(arg0!=0)
		{
			holder.tvTitle.setTextColor(mBlack);
			convertView.setBackgroundColor(Color.WHITE);
		}
		holder.tvTitle.setText(mList.get(arg0));
		
		return convertView;
	}
	static class ViewHolder
	{
		ImageView imgUser;
		TextView tvTitle;
	}
}
